﻿using RamGecTools;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Drawing;

namespace Settings4Net_Test
{
    
    
    /// <summary>
    ///This is a test class for Settings4NetTest and is intended
    ///to contain all Settings4NetTest Unit Tests
    ///</summary>
    [TestClass()]
    public class Settings4NetTest
    {


        private TestContext testContextInstance;

        static private string path = @"..\..\..\Settings4Net Test";

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Open
        ///</summary>
        [TestMethod()]
        public void OpenTest()
        {
            Settings4Net target = new Settings4Net(); // TODO: Initialize to an appropriate value
            string filename = path + "\\test1_valid.xml"; // TODO: Initialize to an appropriate value
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.Open(filename);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Open
        ///</summary>
        [TestMethod()]
        public void OpenTest1()
        {
            Settings4Net target = new Settings4Net(); // TODO: Initialize to an appropriate value
            string filename = path + "\\test1_valid.xml"; // TODO: Initialize to an appropriate value
            bool PreventManualModifications = false; // TODO: Initialize to an appropriate value
            bool AppendSettings = false; // TODO: Initialize to an appropriate value
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.Open(filename, PreventManualModifications, AppendSettings);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Open
        ///</summary>
        [TestMethod()]
        public void OpenTest2()
        {
            Settings4Net target = new Settings4Net(); // TODO: Initialize to an appropriate value
            string filename = path + "\\test1_valid.xml"; // TODO: Initialize to an appropriate value
            bool PreventManualModifications = false; // TODO: Initialize to an appropriate value
            bool expected = true; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.Open(filename, PreventManualModifications);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Open
        ///</summary>
        [TestMethod()]
        public void OpenTest3()
        {
            Settings4Net target = new Settings4Net(); // TODO: Initialize to an appropriate value
            string filename =  path + "\\test1_valid.xml"; // TODO: Initialize to an appropriate value
            bool PreventManualModifications = true; // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.Open(filename, PreventManualModifications);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Open
        ///</summary>
        [TestMethod()]
        public void OpenTest4()
        {
            Settings4Net target = new Settings4Net(); // TODO: Initialize to an appropriate value
            string filename = path + "\\test2_invalid.xml"; // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;
            actual = target.Open(filename);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Add
        ///</summary>
        public void AddTestHelper<T>()
        {
            Settings4Net target = new Settings4Net(); // TODO: Initialize to an appropriate value
            string Name = "TestItem"; // TODO: Initialize to an appropriate value
            Color Value = Color.Red; // TODO: Initialize to an appropriate value
            string Description = "Desc"; // TODO: Initialize to an appropriate value
            string Category = "Cat"; // TODO: Initialize to an appropriate value
            string Tag = string.Empty; // TODO: Initialize to an appropriate value
            bool Readonly = false; // TODO: Initialize to an appropriate value
            target.Add<Color>(Name, Value, Description, Category, Tag, Readonly);

            Assert.AreEqual(Value, target.Settings["TestItem"]);
            Assert.AreEqual(Description, target.GetItemDescription("TestItem"));
            Assert.AreEqual(Category, target.GetItemCategory("TestItem"));
            Assert.AreEqual(Tag, target.GetItemTag("TestItem"));
            Assert.AreEqual(Readonly, target.GetReadonlyProperty("TestItem"));
        }

        [TestMethod()]
        public void AddTest()
        {
            AddTestHelper<Color>();
        }

        /// <summary>
        ///A test for ResetToDefaultValue
        ///</summary>
        [TestMethod()]
        public void ResetToDefaultValueTest()
        {
            Settings4Net target = new Settings4Net(); // TODO: Initialize to an appropriate value
            target.Settings["Test"] = "Value";
            target.SetDefaultItemValue("Test", "DefaultValue");
            target.Settings["Test2"] = 2;
            
            target.ResetToDefaultValue("Test", "Other");
            Assert.AreEqual("DefaultValue", target.Settings["Test"]);

            target.ResetToDefaultValue("Test2");
            Assert.AreEqual(2, target.Settings["Test2"]);
            target.ResetToDefaultValue("Test2", 10);
            Assert.AreEqual(10, target.Settings["Test2"]);
        }

        /// <summary>
        ///A test for GetItemOrDefaultValue
        ///</summary>
        [TestMethod()]
        public void GetItemOrDefaultValueTest()
        {
            Settings4Net target = new Settings4Net(); // TODO: Initialize to an appropriate value
            target.Settings["test"] = 1.11;
            object actual = target.GetItemOrDefaultValue("test", 0f);
            Assert.AreEqual(1.11, actual);
            actual = target.GetItemOrDefaultValue("none", 7.12);
            Assert.AreEqual(7.12, actual);
        }

        /// <summary>
        ///A test for GetMinItemValue
        ///</summary>
        [TestMethod()]
        public void GetMinItemValueTest()
        {
            Settings4Net target = new Settings4Net(); // TODO: Initialize to an appropriate value
            target.Settings["test"] = 7;
            target.SetMinItemValue("test", 2);
            object actual;
            actual = target.GetMinItemValue("test");
            Assert.AreEqual(2, actual);

            target.Settings["test"] = 1;
            Assert.AreEqual(7, target.Settings["test"]);
        }

        /// <summary>
        ///A test for GetMaxItemValue
        ///</summary>
        [TestMethod()]
        public void GetMaxItemValueTest()
        {
            Settings4Net target = new Settings4Net(); // TODO: Initialize to an appropriate value
            target.Settings["test"] = 7;
            target.SetMaxItemValue("test", 11);
            object actual;
            actual = target.GetMaxItemValue("test");
            Assert.AreEqual(11, actual);

            target.Settings["test"] = 15;
            Assert.AreEqual(7, target.Settings["test"]);
        }
    }
}
